﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class GridNode
{
    public bool _canWalk;
    public Vector3 _worldPos;
    public int _gridX;
    public int _gridZ;
    public List<GridObj> _targetUnitList = new List<GridObj>();

    //A * 
    public GridNode _parent;
    //F = G + H
    public int F;
    public int G;
    public int H;
    public void CalF()
    {
        F = G + H;
    }

    public override string ToString()
    {
        return string.Format("{0}_{1}",_gridX,_gridZ);
    }

    public void Init(bool canWalk, Vector3 pos, int gridX, int gridZ)
    {
        _canWalk = canWalk;
        _worldPos = pos;
        _gridX = gridX;
        _gridZ = gridZ;
    }

    public void AddItem(GridObj unit)
    {
        if (!_targetUnitList.Contains(unit))
        {
            _targetUnitList.Add(unit);
            _canWalk = false;
        }
    }

    public void Clean(GridObj unit)
    {
        if (_targetUnitList.Contains(unit))
        {
            _targetUnitList.Remove(unit);
            if (_targetUnitList.Count == 0)
            {
                _canWalk = true;
            }
        }
    }
}
